<template>
  <div>
    <van-field label='标题' v-model='form.title'/>
    <van-field label='价格' v-model='form.price'/>
    <select v-model='form.city_id'>
      <option :value="i.id" v-for='i in citylist'>{{ i.name }}</option>
    </select>
    <van-uploader :after-read='upload'/>
    <van-button @click='add'>提交</van-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {pic: '', city_id: 0},
      citylist: []
    }
  },
  methods: {
    upload(file) {
      //图片上传操作
      let formdata = new FormData()
      formdata.append('file', file.file)
      formdata.append('cityid', this.form.city_id)
      this.axios.post('upload', formdata).then(res => {
        if (res.data.code == 200) {
          this.form.pic = res.data.url
        }
      })


    },
    add() {
      this.axios.post('proM', this.form).then(res => {

      })
    },
    //获取城市
    getcitylist() {
      this.axios.get('cityM').then(res => {
        if (res.data.code == 200) {
          this.citylist = res.data.list
          //默认选中第一个
          this.form.city_id = this.citylist[0]['id']
        }
      })
    }
  },
  mounted() {
    this.getcitylist()
  },
}
</script>
<style>

</style>
